import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/base/Refresher.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/network/Api.dart';
import 'package:huajianshe_app/pages/main/model/MomentModel.dart';
import 'package:huajianshe_app/pages/user_info/UserMomentItem.dart';
import 'package:huajianshe_app/widget/appbar/CAppBar.dart';

//我的动态
class MyMomentsPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return _MyMomentsPageState();
  }
}

class _MyMomentsPageState extends BaseState<MyMomentsPage> {

  @override
  void initState() {
    super.initState();
    refresher = Refresher<MomentMonthData>(this);
    refresher?.enablePullUp = false;
    refresher?.enablePullDown = false;
    load();
  }

  load() {
    var data = {
      // 'member_sn': widget.userInfo?.memberSn,
      'get_type': 7,//widget.momentType,
      'group_by_month': 1 //是否按月分组 1.是 （默认否）,如果按月分组，没有分页，分页参数无效
    };
    sendReq(Api.momentList(), MomentMonthListResp(), data: data);
  }

  @override
  void onReqSuccess<T>(T t, int code, String msg, String path) {
    if (t is MomentMonthListResp) {
      refresher?.load(t.data);
      setState(() => {});
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: CAppBar(title: '我的动态', backImgUrl: 'ic_black_arrow', overlayStyle: SystemUiOverlayStyle.dark, actions: [
        GestureDetector(onTap: myMessages, child: Text('消息列表', style: TS(14, C.gray333))),
      ],),
      body: refresher?.build(buildChild()),
    );
  }

  buildChild() {
    Widget? empty = buildEmptyView();
    if (empty != null) {
      return empty;
    }
    return ListView.separated(
        // controller: this.controller,
        itemBuilder: (_, index) {
          return UserMomentItem(refresher?.data?[index], null, hideTopLine: index == 0,);
        },
        separatorBuilder: (_, index) => H(0),
        itemCount: ((refresher?.data?.length ?? 0))
    );
  }

  myMessages() {

  }
}